/*
 * PGN_Reader : A simple pgn reader for chess games.
 * Copyright (C) 2011 Laurent BERNABE
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece;

import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.HalfMoveData;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.move.PieceMovingDeltas;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.AllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.BishopAllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.KingAllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.KnightAllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.PawnAllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.QueenAllowedMoves;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves.RookAllowedMoves;

public enum PieceForce {
	pawn, knight, bishop, rook, queen, king;

	public static PieceForce getPieceForceFromUppercaseInitial(char pieceInitial){
		PieceForce pieceForceToReturn = null;
		switch (pieceInitial) {
		case 'N':
			pieceForceToReturn = PieceForce.knight;
			break;
		case 'B':
			pieceForceToReturn = PieceForce.bishop;
			break;
		case 'R':
			pieceForceToReturn = PieceForce.rook;
			break;
		case 'Q':
			pieceForceToReturn = PieceForce.queen;
			break;
		case 'K':
			pieceForceToReturn = PieceForce.king;
			break;
		default:
			pieceForceToReturn = PieceForce.pawn;
		}
		return pieceForceToReturn;
	}
	
	public boolean isALongRangedPieceForce(){
		return this == PieceForce.bishop || this == PieceForce.rook || this == PieceForce.queen;
	}
	
	public PieceMovingDeltas[] getAllowedMoves(int playerTurn,
			HalfMoveData halfMoveData, PawnStatus[][] pawnStatusClone) {
		PieceMovingDeltas [] movesToReturn;
		AllowedMoves pieceAllowedMoves = null;
		switch(this){
		case pawn:
			pieceAllowedMoves = new PawnAllowedMoves();
			break;
		case knight:
			pieceAllowedMoves = new KnightAllowedMoves();
			break;
		case bishop:
			pieceAllowedMoves = new BishopAllowedMoves();
			break;
		case rook:
			pieceAllowedMoves = new RookAllowedMoves();
			break;
		case queen:
			pieceAllowedMoves = new QueenAllowedMoves();
			break;
		case king:
			pieceAllowedMoves = new KingAllowedMoves();
			break;
		}
		if (pieceAllowedMoves != null)
			movesToReturn = pieceAllowedMoves.getAllowedMoves(playerTurn, halfMoveData, pawnStatusClone);
		else
			movesToReturn = null;
		return movesToReturn;
	}
	
}
